import os
from dotenv import load_dotenv
from nl2sql import NL2SQL

def test_db_info():
    # Load environment variables from .env file
    load_dotenv()

    # 创建NL2SQL实例
    n2s = NL2SQL()
    
    # 获取所有表
    print("\n=== 数据库中的表 ===")
    tables = n2s.get_tables()
    for table in tables:
        print(f"- {table['table_name']}")
    
    # 获取system_tenant表的信息
    print("\n=== system_tenant表结构 ===")
    columns = n2s.get_table_columns('system_tenant')
    for column in columns:
        print(f"- {column['column_name']}: {column['data_type']} (可空: {column['is_nullable']})")
    
    # 获取system_tenant表的数据
    print("\n=== system_tenant表数据 ===")
    data = n2s.get_table_data('system_tenant')
    for row in data:
        print("\n租户信息:")
        for key, value in row.items():
            print(f"  {key}: {value}")


def test_nl2sql():

    n2s = NL2SQL(model='deepseek')
    result = n2s.nl2sql("查询所有租户的基本信息")
    print(result)

def test_nl2result():

    n2s = NL2SQL(model='deepseek')
    result = n2s.nl2result("查询所有租户的基本信息")
    print(result)

if __name__ == "__main__":
    print("------数据库信息测试开始------")
    test_db_info()
    print("--------------------------------")
    print("------nl2sql测试开始------")
    test_nl2sql()
    print("--------------------------------")
    print("------nl2result测试开始------")
    test_nl2result()